/*
 * This project provides a number of implementations for indexing and evaluating
 * <i>Continuous Top-k Queries over Text Streams</i>
 * and has been developped as part of the work described in the article:
 * 
 * Vouzoukidou, N., Amann, B., & Christophides, V. (2012, October). 
 * Processing continuous text queries featuring non-homogeneous scoring functions.
 * In Proceedings of the 21st ACM international conference on Information and 
 * knowledge management (pp. 1065-1074). ACM.
 * http://dl.acm.org/citation.cfm?id=2398404
 * 
 * This software is distributed under the GNU General Public License and as an
 * additional condition of usage, please cite the aforementioned article.
 * 
 * Copyright (C) 2012 ICS/FORTH, Greece and 
 *               2012 LIP6, France
 * 
 * Author: Vouzoukidou Nelly, email: nelly.vouzoukidou (at) gmail (dot) com
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
package examples;

import gr.forth.ics.continuoustopk.Constants;
import gr.forth.ics.continuoustopk.Item;
import gr.forth.ics.continuoustopk.Query;
import gr.forth.ics.continuoustopk.Term;

/**
 * An example of Query and Item creation
 *
 * @author Vouzoukidou Nelly, email: nelly.vouzoukidou (at) gmail (dot) com
 */
public class QueryItemIndexCreation {
    public static void main(String[] args) {
        // An item is a document from a stream
        
        long timestamp = System.currentTimeMillis();
        double itemScore = 0.3; // a value showing the importance of this item or 0 if indifferent
        Item item = new Item(timestamp, itemScore, "A", "B", "C");
        printItemDetails(item);
        
        String[] terms = {"A", "B", "C"};
        Query q1 = Query.newTopOne(terms);
        Query q2 = Query.newTopOne(terms, 0.5);
        
        System.out.println("The terms of q1 are:");
        for (int i = 0; i < q1.termCount(); i++) {
            System.out.println(q1.getTerm(i));
        }
        
        System.out.println("The terms of q2 are:");
        for (Term term : q2) {
            System.out.println(term);
        }
        
        printUpdateStatus(item, q1, "q1");
        printUpdateStatus(item, q2, "q2");
    }
    
    private static void printItemDetails(Item item) {
        // retrieving values:
        System.out.println("The item created has " + item.termCount() + " terms.");
        if (item.contains(Term.newTerm("B"))) {
            System.out.println("It contains term B");
        } else {
            System.out.println("ERROR: term B not found.");
        }
        
        if (!item.contains(Term.newTerm("D"))) {
            System.out.println("But, it does not contain D");
        } else {
            System.out.println("ERROR: term D found but is not in item.");
        }
        
        System.out.println("String representation: \"" + item + "\"");
        System.out.println("--------------------------");
    }
    
    private static void printUpdateStatus(Item item, Query query, String queryName) {
        if (Constants.isUpdated(query, item)) {
            System.out.println(queryName + " is updated by item because: ");
        } else {
            System.out.println(queryName + " is NOT updated by item becase: ");
        }
        System.out.println("score(" + queryName + ", item)=" 
                + Constants.rankingFunction.score(query, item) 
                + " and " + queryName + ".minScore=" + query.minScore());
    }
}
